<?php
/**
 * 支付宝支付；
 * 1.该类是Action类方法，使用只需要在控制器中初始化。
 * 2.通知，配置文件common/params.php中配置回调域名地址，如果异步通知和同步通知，不填写，写入默认的地址
 * 3.不想用默认的配置回调地址，需要在方法参数中指定域名地址和回调地址。
 * 4.支付之前会判断签名验证，订单状态，订单金额是否是支付，小于0不支付
 * @author ran.ran
 * @example
 */
namespace components;

use yii\base\Exception;
use yii\web\NotFoundHttpException;
use Yii;
use leyestd\alipay\WapAlipay;
use common\helper\UrlManager;

class WapAlipayAction extends BasePayMentAction
{
    public function run() {
        try{
         //验证
         $res = $this->validateOrderInfo();
         //用户已经支付及支付金额小于0 。跳转到详情页
         if(!$res['flag']) {
             $url = Yii::$app->urlManager->createUrl(['order-details/order-list']);
             return Yii::$app->response->redirect($url);
         }
         
        } catch(Exception $e){
            
           throw  new NotFoundHttpException();
        }
      
      //设置回调地址
      $this->notifyUrl = UrlManager::createUrl(Yii::$app->params['domains']['api_url'], ['wap-notify-alipay']);
      $this->returnUrl = UrlManager::createUrl(Yii::$app->params['domains']['api_url'], ['wap-return-alipay']);
      
      $wapAlipay = new WapAlipay();
      return $wapAlipay->getPayUrl($this->notifyUrl, $this->returnUrl, $this->payment->order_sn, $this->subject,$this->payment->order_amount, $this->body, $this->showUrl, $this->payment->pay_id, $this->payment->bank);
             
    }
    
}

?>